// File Name: rs485_interface.h
// Author: kukukukuku~
// Date: 2024-12-20

#ifndef __RS485_INTERFACE_H
#define __RS485_INTERFACE_H

#include "./RS485/inc/rs485_ctrl.h"
#include "./RS485/inc/rs485_init.h"

//RS485接收状态
typedef enum RS485_RX_STATE_T
{
    RS485_RX_STATE_UNCOMPLETE = 0,
    RS485_RX_STATE_COMPLETE = !RS485_RX_STATE_UNCOMPLETE,
}RS485_RX_STATE_T;

//RS485对象
typedef struct RS485_OBJECT_T
{
    uint8_t *pTxBuffer;
    uint8_t *pRxBuffer;
    uint16_t rxIndex;
    RS485_RX_STATE_T rxFinishFlag;
}RS485_OBJECT_T, *pRS485_OBJECT_T;


void rs485_object_init(RS485_OBJECT_T * const rs485Obj, const uint8_t * const txBuffer, const uint8_t * const rxBuffer);

void rs485_int_idle_callback(RS485_OBJECT_T * const rs485Obj);
void rs485_int_rx_callback(RS485_OBJECT_T * const rs485Obj);

void rs485_rx_finish_flag_clear(RS485_OBJECT_T * const rs485Obj);
RS485_RX_STATE_T rs485_rx_finish_flag_get(const RS485_OBJECT_T * const rs485Obj);

void rs485_rx_data_len_clear(RS485_OBJECT_T * const rs485Obj);
uint16_t rs485_rx_data_len_get(const RS485_OBJECT_T * const rs485Obj);

void rs485_received_data_handle(RS485_OBJECT_T * const rs485Obj);
uint8_t * rs485_rx_buffer_get(const RS485_OBJECT_T * const rs485Obj);
void rs485_rx_buffer_clear(RS485_OBJECT_T * const rs485Obj);
void rs485_send_data(RS485_OBJECT_T * const rs485Obj, const uint8_t * const data, const uint16_t dataLen);

#endif //__RS485_INTERFACE_H
